package com.ruoyi.sbgl.cjxxgl.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.sbgl.cjxxgl.domain.Cjxxgl;
import com.ruoyi.sbgl.cjxxgl.service.ICjxxglService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.List;

/**
 * 厂家信息管理Controller
 *
 * @author huacai
 * @date 2024-09-05
 */
@RestController
@RequestMapping("/sbgl/cjxxgl")
public class CjxxglController extends BaseController {
    @Resource
    private ICjxxglService cjxxglService;

    /**
     * 查询厂家信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('sbgl:cjxxgl:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cjxxgl cjxxgl) {
        startPage();
        List<Cjxxgl> list = cjxxglService.selectCjxxglList(cjxxgl);
        return getDataTable(list);
    }

    /**
     * 不分页查询厂家列表
     * @return
     */
    @GetMapping("/selectCjList")
    public AjaxResult selectCjList() {
        List<Cjxxgl> list = cjxxglService.selectCjList();
        return AjaxResult.success(list);
    }

    /**
     * 导出厂家信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('sbgl:cjxxgl:export')")
    @Log(title = "厂家信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cjxxgl cjxxgl) {
        List<Cjxxgl> list = cjxxglService.selectCjxxglList(cjxxgl);
        ExcelUtil<Cjxxgl> util = new ExcelUtil<Cjxxgl>(Cjxxgl.class);
        util.exportExcel(response, list, "厂家信息管理数据");
    }

    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<Cjxxgl> util = new ExcelUtil<Cjxxgl>(Cjxxgl.class);
        util.importTemplateExcel(response, "厂家信息管理数据");
    }

    /**
     * 导入数据
     */
    @Log(title = "厂家信息管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('sbgl:cjxxgl:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<Cjxxgl> util = new ExcelUtil<Cjxxgl>(Cjxxgl.class);
        InputStream inputStream = file.getInputStream();
        List<Cjxxgl> list = util.importExcel(inputStream);
        inputStream.close();
        int count = cjxxglService.batchInsertCjxxgl(list);
        return AjaxResult.success("导入成功" + count + "条信息！");
    }

    /**
     * 获取厂家信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('sbgl:cjxxgl:query')")
    @GetMapping(value = "/{cjxxglId}")
    public AjaxResult getInfo(@PathVariable("cjxxglId") Integer cjxxglId) {
        return success(cjxxglService.selectCjxxglByCjxxglId(cjxxglId));
    }

    /**
     * 新增厂家信息管理
     */
    @PreAuthorize("@ss.hasPermi('sbgl:cjxxgl:add')")
    @Log(title = "厂家信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cjxxgl cjxxgl) {
        return toAjax(cjxxglService.insertCjxxgl(cjxxgl));
    }

    /**
     * 修改厂家信息管理
     */
    @PreAuthorize("@ss.hasPermi('sbgl:cjxxgl:edit')")
    @Log(title = "厂家信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cjxxgl cjxxgl) {
        return toAjax(cjxxglService.updateCjxxgl(cjxxgl));
    }

    /**
     * 删除厂家信息管理
     */
    @PreAuthorize("@ss.hasPermi('sbgl:cjxxgl:remove')")
    @Log(title = "厂家信息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cjxxglIds}")
    public AjaxResult remove(@PathVariable Integer[] cjxxglIds) {
        return toAjax(cjxxglService.deleteCjxxglByCjxxglIds(cjxxglIds));
    }
}
